<template>
  <div class="app-container" style="background: #f3f4f6;flex: 1;">
    <div class="teacher_search">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="教师工号" prop="teacherNo">
          <el-input
            v-model="queryParams.teacherNo"
            placeholder="请输入教师工号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="教师姓名" prop="teacherName">
          <el-input
            v-model="queryParams.teacherName"
            placeholder="请输入教师姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
            <el-option
              v-for="dict in dict.type.classai_common_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['classai:teacher:add']"
        >新增教师</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['classai:teacher:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['classai:teacher:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['classai:teacher:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="teacherList" @selection-change="handleSelectionChange" class="teacher_list">
      <el-table-column label="序号" type="index" width="50" align="center" />
      <el-table-column label="工号" align="center" prop="teacherNo" />
      <el-table-column label="姓名" align="center" prop="teacherName">
        <template slot-scope="scope">
          <div style="display: flex;align-items: center;justify-content: center;gap:10px;">
            <image-preview :src="scope.row.photoPath" :width="32" :height="32" borderRadius="50%" />
            <div style="min-width: 60px;text-align: left;">{{scope.row.teacherName}}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <div class="teacher_gender">
            <dict-tag :options="dict.type.teacher_sex" :value="scope.row.gender"/>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="联系方式" align="center" prop="teacherPhone" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.classai_common_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['classai:teacher:edit']"
          >
            <img src="@/assets/images/teacher_edit.png" style="width:16px;height:16px;" alt="">
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
            v-hasPermi="['classai:teacher:edit']"
          >
            <img src="@/assets/images/teacher_detail.png" style="width:12px;height:16px;" alt="">
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['classai:teacher:remove']"
          >
            <img src="@/assets/images/teacher_del.png" style="width:14px;height:16px;" alt="">
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination_d">
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listTeacher, getTeacher, delTeacher, addTeacher, updateTeacher } from "@/api/classai/teacher";

export default {
  name: "Teacher",
  dicts: ['classai_common_status', 'teacher_sex', 'teacher_title'],
  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教师信息表格数据
      teacherList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teacherNo: null,
        teacherName: null,
        status: null,
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询教师信息列表 */
    getList() {
      this.loading = true;
      listTeacher(this.queryParams).then(response => {
        this.teacherList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleAdd() {
      this.$router.push(`/teacher/addTeacher`)
    },
    handleUpdate(row) {
      this.$router.push(`/teacher/editTeacher?id=${row.id}`)
    },
    handleDetail(row) {
      this.$router.push(`/teacher/teacherDetail?id=${row.id}`)
    },
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除教师信息编号为"' + ids + '"的数据项？').then(function() {
        return delTeacher(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('classai/teacher/export', {
        ...this.queryParams
      }, `teacher_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
.teacher_list {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  ::v-deep {
    .el-tag {
      border-radius: 15px;
      border: none;
      min-width: 50px;
    }
    .teacher_gender {
      .el-tag {
        background: transparent;
        color: #333;
      }
    }
    .has-gutter {
      background: #F3F4F6;
      height: 56px;
      .el-table__cell {
        background: #F3F4F6;
      }
    }
  }
}
.teacher_search {
  margin-bottom: 10px;
  padding: 15px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  ::v-deep {
    .el-form-item {
      margin-bottom: 0;
    }
  }
}
.pagination_d {
  margin-top: 10px;
  padding: 15px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  ::v-deep {
    .pagination-container {
      margin-top: 0;
      background: transparent;
    }
  }
}


</style>
